package com.tz.farm_feeding.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSONObject;
import com.tz.farm_feeding.domain.*;
import com.tz.farm_feeding.mapper.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SysinfoController {

  @Autowired
  SysinfoMapper sysinfoMapper;

  @PostMapping(value = "/setinfo")
  public String setinfo(@RequestBody JSONObject jsonparm, HttpServletRequest request, HttpSession session) {
    // TODO: process POST request
    String info = jsonparm.getString("info");
    Sysinfo sys = new Sysinfo();
    sys.setId(1);
    sys.setInfo(info);
    sysinfoMapper.updateByPrimaryKeySelective(sys);
    JSONObject result = new JSONObject();
    result.put("result", status.s_ok);
    return result.toJSONString();
  }

  @PostMapping(value="/getinfo")
  public String getinfo(@RequestBody JSONObject  jsonparm, HttpServletRequest request, HttpSession session) {
      //TODO: process POST request
      String info = jsonparm.getString("info");
      Sysinfo sys = sysinfoMapper.selectByPrimaryKey(1);
      JSONObject result =new JSONObject();
      result.put("data", JSONObject.parse( sys.toString()));
      result.put("result", status.s_ok);
      return result.toJSONString();
  }
}